import dialog from './index.vue'
import Vue from 'vue'
import store from '../../store'
const DialogConstructor = Vue.extend(dialog)
const theDialog = function (params) {
    return new Promise((resolve, reject) => {
        const dialogDom = new DialogConstructor({
            el: document.createElement('div')
        })
        document.body.appendChild(dialogDom.$el) // new一个对象，然后插入body里面
        dialogDom.dialogVisible = true
        dialogDom.title = params.title
        dialogDom.type = params.type
        dialogDom.formData = params.formData
        dialogDom.$store = store
        dialogDom.exit = function () {
            dialogDom.dialogVisible = false
            document.body.removeChild(dialogDom.$el) // 移除dom
        }
        dialogDom.cancel = function (value) {
            dialogDom.exit()
            reject(value)
        }
        dialogDom.confirm = function (value) {
            dialogDom.dialogVisible = false
            resolve(value)
        }
    })
}
export default theDialog